package com.lottery.im.module.result.presenter;

import android.app.Activity;
import com.lottery.im.api.ApiClient;
import com.lottery.im.api.RetryWithDelay;
import com.lottery.im.api.observer.BaseListObserver;
import com.lottery.im.api.observer.BaseObserver;
import com.lottery.im.api.result.ApiListResult;
import com.lottery.im.api.result.ApiResult;
import com.lottery.im.api.result.entity.AdInfo;
import com.lottery.im.api.result.entity.ResultInfo;
import com.lottery.im.base.BaseFragmentPresenter;
import com.lottery.im.module.result.view.ResultView;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class ResultPresenter extends BaseFragmentPresenter<ResultView> {

  public ResultPresenter(Activity activity,
      ResultView iView,
      LifecycleProvider<FragmentEvent> provider) {
    super(activity, iView, provider);
  }

  /*
   * banner
   * */
  public void getAd() {
    ApiClient.getApiRetrofitInstance()
        .getAD()
        .throttleFirst(2, TimeUnit.SECONDS)
        .retryWhen(new RetryWithDelay(1000, 10000))
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .compose(provider.bindToLifecycle())
        .subscribe(new BaseObserver<AdInfo>() {
          @Override public void onStart() {

          }

          @Override public void onSuccess(AdInfo adInfo) {
            iView.getAdSuccess(adInfo);
          }

          @Override public void onFail(String code, String msg) {

          }

          @Override public void onException(String msg) {

          }

          @Override public void onFinish() {

          }
        });
  }

  /*
   * 查询所有彩种开奖结果-预测
   * */
  public void queryAllGameTypeResult() {
    ApiClient.getApiRetrofitInstance()
        .queryAllGameTypeResult()
        .throttleFirst(2, TimeUnit.SECONDS)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .compose(provider.bindToLifecycle())
        .subscribe(new BaseListObserver<ResultInfo>() {
          @Override public void onStart() {
          }

          @Override public void onSuccess(List<ResultInfo> list) {
            iView.querySuccess(list);
          }

          @Override public void onFail(String code, String msg) {
          }

          @Override public void onException(String msg) {
          }

          @Override public void onFinish() {
          }
        });
  }
}
